package com.fallback;
import com.hmall.common.Client.ItemClient;
import com.hmall.common.dto.Item;
import com.hmall.common.dto.PageDTO;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.ArrayList;

@Slf4j
@Component
public class ItemClientFactory implements FallbackFactory<ItemClient> {
    @Override
    public ItemClient create(Throwable throwable) {
        return new ItemClient() {
            @Override
            public PageDTO<Item> QueryPageByItem(Integer page, Integer size) {
                log.error("调用商品查询服务异常", throwable);
                return new PageDTO<>(9991L,new ArrayList<>());
            }

            @Override
            public Item queryItemById(Long id) {
                log.error("调用：根据id查询商品服务异常", throwable);
                Item item = new Item();
                item.setName("你在想什么？代码都是错的，服务还会超时还想要数据？？？？");
                return item;
            }

            @Override
            public void decreaseStock(Long itemId, Integer num) {
                log.error("调用：更新商品库存服务异常", throwable);

            }

            @Override
            public void addStock(Long itemId, Integer num) {
                log.error("调用：【更新商品库存异常】", throwable);
            }
        };
    }
}
